package com.wc.blue_bridge_history.Java12Q.E_123;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/20 18:49
 * @description https://www.lanqiao.cn/problems/1591/learning/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2000000;
    static long[] num = new long[N];
    static long[] sum = new long[N];
    static int T;

    public static void main(String[] args) {
        for (int i = 1; i < N; i++) {
            num[i] = num[i - 1] + i;
            sum[i] = (long) (i + 1) * i / 2;
        }

        for (int i = 1; i < N; i++) sum[i] += sum[i - 1];

        T = sc.nextInt();
        while (T-- > 0) {
            long l = sc.nextLong(), r = sc.nextLong();
            out.println(dp(r) - dp(l - 1));
        }

        out.flush();
    }

    static long dp(long n) {
        if (n == 0) return 0;
        int l = 1, r = N - 1;
        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (num[mid] <= n) l = mid;
            else r = mid - 1;
        }
        long res = sum[l];
        n -= num[l];
        res += (n + 1) * n / 2;
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
